package cn.thr.ymcc.consumer;

import cn.thr.ymcc.constant.Cos;
import cn.thr.ymcc.service.ICourseOrderService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@RocketMQMessageListener(
        consumerGroup = "PayTimeoutHandlerInOrder",
        topic = Cos.pay.TOPIC_PAY_TIMEOUT,
        selectorExpression = Cos.pay.TAGS_PAY_TIMEOUT
)
public class PayTimeoutHandler implements RocketMQListener<MessageExt> {
    @Autowired
    private ICourseOrderService courseOrderService;
    @Override
    public void onMessage(MessageExt messageExt) {
        byte[] body = messageExt.getBody();
        //订单编号
        String orderNo = new String(body);
        log.info("订单服务中收到支付超时的延迟消息，正在处理...{}",orderNo);
        // 修改状态
        courseOrderService.payTimeout(orderNo);

    }
}
